#include <iostream>
using namespace std;
int main()
{
  int Ra, Ca ,i;
  cin >> Ra >> Ca;
  int **matrix1 = new int*[Ra];
  for (i = 0; i < Ra; i++)
  {
    matrix1[i] = new int[Ca];
    for (int j = 0; j < Ca; j++)
      cin >> matrix1[i][j];
  }
  int Rb, Cb;
  cin >> Rb >> Cb;
  int **matrix2 = new int*[Rb];
  for (i = 0; i < Rb; i++)
  {
    matrix2[i] = new int[Cb];
    for (int j = 0; j < Cb; j++)
      cin >> matrix2[i][j];
  }
  if(Ca != Rb)
  {
    printf("Error: %d != %d\n", Ca, Rb);
    system("PAUSE");
    return 0;
  }
  cout << Ra << " " << Cb << endl;
  for (i = 0; i < Ra; i++)
  {
    for (int j = 0; j < Cb; j++)
    {
      int sum = 0;
      for (int k = 0; k < Ca; k++)
        sum = sum + matrix1[i][k] * matrix2[k][j];
      if(j != 0)
        cout <<" ";
      cout << sum;
    }
    cout << endl;
  }
  system("PAUSE");
  return 0;
}